//
//  HD_HSP_GL_ViewController.m
//  HDLiaoNingMeseum
//
//  Created by HDHaoShaoPeng on 2017/8/7.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HD_HSP_GL_ViewController.h"
#import "HD_HSP_Web_ViewController.h"
//#import "HDDownloadUtility.h"
//#import "Strategy.h"

@interface HD_HSP_GL_ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *myTableView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;




@property (strong, nonatomic) NSArray *dataArray;
@property (strong, nonatomic) NSArray *imageArray;
@property (assign, nonatomic) NSInteger selectedRow;
//@property (strong, nonatomic) HDDownloadUtility *myDownloader;
@end

@implementation HD_HSP_GL_ViewController
{
    NSString *_prefixStr;
}

static HDDeclare *declare;
#define Setting_Row (self.dataArray.count)
#define Add_Count 2

#pragma mark
#pragma mark -------- Init Methods --------

- (void)viewDidLoad
{
    [super viewDidLoad];
    declare = [HDDeclare sharedDeclare];
    self.titleLabel.text = declare.strategy;
    self.titleLabel.font = [UIFont fontWithName:@"FZQKBYSJW--GB1-0" size:18.0];
    
    NSString *nameStr = @"chinesename";
    if (declare.languageIndex == 1)
        nameStr = @"englishname";
    else if (declare.languageIndex == 2)
        nameStr = @"japanesename";
    else if (declare.languageIndex == 3)
        nameStr = @"koreanname";
    
//    NSArray *unitArray = [declare fetchData:@"Strategy"];
//    NSPredicate *predic = [NSPredicate predicateWithFormat:@"SELF.%@ != %@", nameStr, @""];
    self.dataArray = @[declare.introduce,declare.strategy_guide,declare.strategy_traffic,declare.Questionnaire,declare.Feedback];
    
    self.imageArray = @[@"strategy_intro",@"strategy_guide",@"strategy_traffic",@"strategy_survey",@"strategy_feedback"];
    _myTableView.separatorColor = [UIColor clearColor];
    
    if ([declare.language.uppercaseString containsString:@"CHI"]) {
        _prefixStr = @"c";
    }
    else if ([declare.language.uppercaseString containsString:@"ENG"]) {
        _prefixStr = @"e";
    }
    else if([declare.language.uppercaseString containsString:@"JAP"]) {
        _prefixStr = @"j";
    }
    else if([declare.language.uppercaseString containsString:@"KOR"]) {
        _prefixStr = @"k";
    }
}

- (void)downloadAction
{
    NSString *mp3Path = [NSString stringWithFormat:@"guide/%@.html", @"1080"];
    NSString *resourcePath = [NSString stringWithFormat:@"%@/Resource/%@/%@",declare.catch_path, [declare.language uppercaseString], mp3Path];
    if ([[NSFileManager defaultManager]fileExistsAtPath:resourcePath])
    {
        [self performSegueWithIdentifier:@"pushToIntroLine" sender:nil];
    }
    
    else
    {
        
    }
}

- (IBAction)backClicked:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)wenJuanDiaoCha
{
    HD_HSP_Web_ViewController *webVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Strategy" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Web_ViewController"];
    webVC.isOnLine = YES;
    webVC.urlPath = [NSString stringWithFormat:@"%@index.php?g=mapi&m=Interactive&a=survey&app_kind=2&language=%ld",[HDDeclare IP_Request_Header],(long)declare.languageIndex];
    webVC.myTitle = declare.Questionnaire;
    [self.navigationController pushViewController:webVC animated:YES];
}

-(void)yiJianFanKui
{
    HD_HSP_Web_ViewController *webVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Strategy" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Web_ViewController"];
    webVC.isOnLine = YES;
    webVC.urlPath = [NSString stringWithFormat:@"%@index.php?g=mapi&m=Interactive&a=feedback&app_kind=2&language=%ld",[HDDeclare IP_Request_Header],(long)declare.languageIndex];
    webVC.myTitle = declare.Feedback;
    [self.navigationController pushViewController:webVC animated:YES];
}

-(void)jiaoTongClicked
{
    HD_HSP_Web_ViewController *webVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Strategy" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Web_ViewController"];
    webVC.isOnLine = NO;
    webVC.filePath = [NSString stringWithFormat:@"%@/APP_Info/%@_traffic.html",declare.catch_path,_prefixStr];
    webVC.myTitle = declare.strategy_traffic;
    [self.navigationController pushViewController:webVC animated:YES];
}

-(void)xuZhiClicked
{
    HD_HSP_Web_ViewController *webVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Strategy" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Web_ViewController"];
    webVC.isOnLine = NO;
    webVC.filePath = [NSString stringWithFormat:@"%@/APP_Info/%@_xuzhi.html",declare.catch_path,_prefixStr];
    webVC.myTitle = declare.strategy_guide;
    [self.navigationController pushViewController:webVC animated:YES];
}

-(void)jianJieClicked
{
    HD_HSP_Web_ViewController *webVC = [[UIStoryboard storyboardWithName:@"HD_HSP_Strategy" bundle:nil] instantiateViewControllerWithIdentifier:@"HD_HSP_Web_ViewController"];
    webVC.isOnLine = NO;
    webVC.filePath = [NSString stringWithFormat:@"%@/APP_Info/%@_overview.html",declare.catch_path,_prefixStr];
    webVC.myTitle = declare.introduce;
    [self.navigationController pushViewController:webVC animated:YES];
}


#pragma mark
#pragma mark -------- Init Methods --------

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"strategyListCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    UIImage *image = [UIImage imageNamed:_imageArray[indexPath.row]];
    if (image == nil)
        image = [UIImage imageNamed:@"list_icon_default"];
    cell.imageView.image = image;
    
    UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 59, self.view.frame.size.width-10, 1)];
    lineImageView.image = [UIImage imageNamed:@"cell_segment_line"];
    [cell.contentView addSubview:lineImageView];
    
    UIImageView *imageSelect = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell_selected"]];
    cell.selectedBackgroundView = imageSelect;
    UIImageView *rightImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_next"]];
    cell.accessoryView = rightImage;
    cell.textLabel.font = [UIFont fontWithName:@"FZQKBYSJW--GB1-0" size:20.0];
    cell.textLabel.textColor = Text_Color;
    
    if (indexPath.row == Setting_Row)
        cell.textLabel.text = declare.Questionnaire;
    else if (indexPath.row == Setting_Row +1)
        cell.textLabel.text = declare.Feedback;
    
    else
    {
        NSString *myItem = _dataArray[indexPath.row];
        cell.textLabel.text = myItem;
    }
    
    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedRow = indexPath.row;
    
    switch (indexPath.row) {
        case 0:
        {
            [self jianJieClicked];
        }
            break;
            
        case 1:
        {
            [self xuZhiClicked];
        }
            break;
            
        case 2:
        {
            [self jiaoTongClicked];
        }
            break;
            
        case 3:
        {
            [self wenJuanDiaoCha];
        }
            break;
            
        case 4:
        {
            [self yiJianFanKui];
        }
            break;
            
        default:
            break;
    }
    
    
    
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    if ([identifier isEqualToString:@"pushToSurveyLine"] || [identifier isEqualToString:@"pushToFeedbackLine"])
    {
        return YES;
    }
    
    return YES;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70.0;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
}

- (void)dealloc
{
    self.imageArray = nil;
    self.dataArray = nil;
    
    [_myTableView removeFromSuperview];
    self.myTableView = nil;
}

@end
